package com.lyh.hkcloud.module.m1300030.adapter;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.lyh.hkcloud.R;
import com.lyh.hkcloud.module.common.MyDialog;
import com.lyh.hkcloud.module.m1300030.IndexActivity;

import java.util.List;
import java.util.Map;

/**
 * @author: zhongfan
 * @program: hkCloud
 * @description: 数据适配器
 * @company—date: 利元数据 2022-02-14 15:12
 **/

public class ListViewAdapter extends BaseAdapter {

    private Context context;
    private List<Map<String,Object>> dataMap;
    private int saveposition;
    private DeleteCallback Callback;
    private IndexActivity mContext;

    /**
     * 构造器
     *
     * @param context  上下文对象
     * @param dataList 数据
     */
    public ListViewAdapter(Context context, List<Map<String,Object>> dataList, IndexActivity mContext) {
        this.context = context;
        this.dataMap = dataList;
        this.mContext = mContext;
    }

    @Override
    public int getCount() {
        return dataMap.size();
    }

    @Override
    public Object getItem(int position) {
        return dataMap.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        Log.v("position---:",String.valueOf(position));

        ViewHolder viewHolder;
        int mark = 0;
        //判断是否有缓存
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.activity_listview_item_1300030, null);
            viewHolder = new ViewHolder(convertView);
            convertView.setTag(viewHolder);
        } else {
            //得到缓存的布局
            viewHolder = (ViewHolder) convertView.getTag();
        }
        Log.v("dataMap---》",dataMap.toString());

            viewHolder.tvOddNumbers.setText(dataMap.get(position).get("billnumber") == null ? "" : dataMap.get(position).get("billnumber").toString());
            viewHolder.tvUser.setText(dataMap.get(position).get("psnname") == null ? "" : dataMap.get(position).get("psnname").toString());
            viewHolder.tvCreationTime.setText(dataMap.get(position).get("createtime") == null ? "" : dataMap.get(position).get("createtime").toString());



        return convertView;
    }

    public interface DeleteCallback { void deletePosition(int saveposition);}

    public void setDeleteCallback(DeleteCallback Callback) {this.Callback = Callback;}

    public void setData(List<Map<String,Object>> data2) {
        this.dataMap = data2;
    }

    /**
     * ViewHolder类
     */
    private final class ViewHolder {
        //出场单号
        TextView tvOddNumbers;
        //使用人
        TextView tvUser;
        //创建时间
        TextView tvCreationTime;

        /**
         * 构造器
         *
         * @param view 视图组件（ListView的子项视图）
         */
        ViewHolder(View view) {
            tvOddNumbers =  view.findViewById(R.id.tv_odd_numbers);
            tvUser =  view.findViewById(R.id.tv_user);
            tvCreationTime = view.findViewById(R.id.tv_creation_time);
        }
    }
}

